#ifndef MESSAGELISTMODEL_H
#define MESSAGELISTMODEL_H

#include <QAbstractListModel>
#include <QSharedDataPointer>

#include "../../global/xnamespace.h"
#include "MessageModel.h"

X_BEGIN_NAMESPACE

class MessageListModelPrivate : public QSharedData
{
public:
    QList<MessageModel> m_messages;
};

// 消息列表模型
class MessageListModel : public QAbstractListModel
{
    Q_OBJECT

    friend class SessionModel;

public:
    explicit MessageListModel(QObject *parent = 0);
    MessageListModel(const MessageListModel& src);
    MessageListModel &operator =(const MessageListModel& rhs);

    static const char *qmlName();

public:
    virtual int rowCount(const QModelIndex &parent) const override;
    virtual QVariant data(const QModelIndex &index, int role) const override;
    virtual QHash<int, QByteArray> roleNames() const override;

public:
    MessageModel insertMessage(int messageId,
                               const QString &senderJid,
                               const QString &senderName,
                               const QString &senderPhoto,
                               const QString &content,
                               const QString &thumbnail,
                               MessageContentType contentType,
                               QDateTime time,
                               bool appendAtFront);

protected:
    QSharedDataPointer<MessageListModelPrivate> d;

private:
    QHash<int, QByteArray> m_roleNames;
    static const char* ROLE_NAMES[];
};

X_END_NAMESPACE

#endif // MESSAGELISTMODEL_H
